package com.douban.business;

import java.io.UnsupportedEncodingException;

import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.XMLAttributes;

import com.douban.business.vo.ItemVO;
import com.douban.business.vo.RecItemVO;
import com.douban.business.vo.RecordingStatusVO;
import com.douban.constants.DoubanConstant;

public class RecsRecorder extends Recorder {

	public RecsRecorder(ItemVO itemvo, RecordingStatusVO rstatus,
			Object elementOrText, XMLAttributes attrs, Augmentations augs,
			int elementMode) {
		super(itemvo, rstatus, elementOrText, attrs, augs, elementMode);
	}

	protected void recording() {
		// invoked from startElement or endElement
		switch (this.getRecordingMode()) {
		case START_ELEMENT:
			switch (((RecItemVO)itemvo).getRecType()) {
			case RecItemVO.GROUP_TOPIC:
				
				
				break;
			default:
				break;
			}
			
			
			break;
		case END_ELEMENT:
			// it is the same element as start element, which means it is
//			if (rstatus.getEleName() != null
//					&& rstatus.getStringBuffer() != null
//					&& rstatus.getFieldName() != null
//					&& element.rawname.equalsIgnoreCase(rstatus.getEleName())) {
//
//				if (element.rawname
//						.equalsIgnoreCase(DoubanConstant.ELEMENT_NAME_FOR_TITLE
//								.getValue())
//						&& rstatus.getFieldName().equalsIgnoreCase(
//								DoubanConstant.TITLE.getValue())) {
//					// push out the characters recorded to the itemvo
//					try {
//						itemvo.setTitle(cleanString(new String(rstatus.getStringBuffer(),DoubanConstant.CHAR_SET.getValue())));
//					} catch (UnsupportedEncodingException e) {
//						itemvo.setIntro("invalid data");
//					}
//					rstatus.clearEleName();
//					rstatus.clearFieldName();
//				} else if (element.rawname
//						.equalsIgnoreCase(DoubanConstant.ELEMENT_NAME_FOR_DATE
//								.getValue())
//						&& rstatus.getFieldName().equalsIgnoreCase(
//								DoubanConstant.DATE.getValue())) {
//					try {
//						itemvo.setDate(cleanString(new String(rstatus.getStringBuffer(),DoubanConstant.CHAR_SET.getValue())));
//					} catch (UnsupportedEncodingException e) {
//						itemvo.setDate("9999-12-12");
//					}
//					rstatus.clearEleName();
//					rstatus.clearFieldName();
//
//				} else if (element.rawname
//						.equalsIgnoreCase(DoubanConstant.ELEMENT_NAME_FOR_INTRO
//								.getValue())
//						&& rstatus.getFieldName().equalsIgnoreCase(
//								DoubanConstant.INTRO.getValue())) {
//					try {
//						itemvo.setIntro(cleanString(new String(rstatus.getStringBuffer(),DoubanConstant.CHAR_SET.getValue())));
//					} catch (UnsupportedEncodingException e) {
//						itemvo.setIntro("invalid data");
////						should never happen, log will be here later
//					}
//					rstatus.clearEleName();
//					rstatus.clearFieldName();
//
//				}
//			}
//			if(itemvo.isReady()){
//				rstatus.clearRecordingId();
//			}
//			rstatus.cleanStringBuffer();
			break;
		case CHARACTERS_ELEMENT:
//			if (rstatus.getEleName() != null
//					&& (rstatus.getEleName().equalsIgnoreCase(
//							DoubanConstant.ELEMENT_NAME_FOR_TITLE.getValue())||
//						rstatus.getEleName().equalsIgnoreCase(
//							DoubanConstant.ELEMENT_NAME_FOR_INTRO.getValue())||
//						rstatus.getEleName().equalsIgnoreCase(
//							DoubanConstant.ELEMENT_NAME_FOR_DATE.getValue())
//									)) {
//				// start recording the characters
//				rstatus.appendStringBuffer(text.ch, text.offset, text.length);
//			}
			break;
		default:
			break;
		}
	}

}
